package com.ftx.controller;

import java.util.Arrays;
import java.util.Base64;
import java.util.Random;

/**
 * Created by fengtingxin on 2021/3/12 2:46 下午
 */
public class RandomTest {

    public static void main(String[] args) {

        System.out.println(2 << 3);

        //根据随机数，然后再取众数
        int groupNum = 10;
        int traversesNum = 1000000; //一百万次
        int num[] = new int[groupNum];
        Random random = new Random();
        for (int i = 0; i < traversesNum; i++){
            int value = random.nextInt(groupNum);
//            System.out.println(value);
            num[value] = num[value]+ 1;
        }
        int maxIndex = 0;
        for (int i = 1; i < groupNum; i++){
            if(num[i] > num[maxIndex]){
                maxIndex = i;
            }
        }
        System.out.println("次数最多为：" + num[maxIndex] + "次 索引为：" + maxIndex);
    }
}
